      SUBROUTINE GAUS2
C
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
C                                                                       
C    FOR GAUSSIAN WAVEFUNCTIONS ONLY.  CALCULATES AT A GIVEN POINT      
C    THE VALUE OF EACH MOLECULAR ORBITAL AND THE MO GRADIENT VECTOR     
C    COMPONENTS.                                                        
C
      COMMON CO(30000),IC(30000),MODE,NCENT,NMO,NPRIMS
C                                                                       
       COMMON /OFFSET/ ITYPE,ICENT,KATOM,IEORB,IE,IMO,ICHARG,IXC,
     + IYC,IZC,IXX,IYY,IZZ,IXS,IYS,IZS,IRR,IR2,IP,IPSI,IGX,IGY,IGZ,
     + ID2,IGXX,IGXY,IGXZ,IGYY,IGYZ,IGZZ
C                                                                       
      DATA ZERO /0.0D0/, ONE /1.0D0/, TWO /2.0D0/, THREE /3.0D0/ 
C
      DO 100 J = 1,NMO
        CO(IPSI+J) = ZERO
        CO(IGX+J) = ZERO
        CO(IGY+J) = ZERO
        CO(IGZ+J) = ZERO
100   CONTINUE
C
      DO 200 I = 1,NPRIMS
        EE = CO(IE+I)*TWO
        X = CO(IXX+IC(ICENT+I))
        Y = CO(IYY+IC(ICENT+I))
        Z = CO(IZZ+IC(ICENT+I))
        IF (CO(IE+I)*CO(IR2+IC(ICENT+I)) .GT. 170.0D0) THEN
          EXPON = ZERO
        ELSE
          EXPON = DEXP(-CO(IE+I)*CO(IR2+IC(ICENT+I)))
        ENDIF
        EXPEE = EXPON*EE
        IF (EXPEE.LT.1.D-25) EXPEE = ZERO
        IF (EXPON.LT.1.D-25) EXPON = ZERO
C                                                                       
C    S                                                                  
C                                                                       
        IF (IC(ITYPE+I) .EQ. 1) THEN 
          BF =  EXPON
          GX = -EXPEE*X
          GY = -EXPEE*Y
          GZ = -EXPEE*Z
C                                                                       
C    X                                                                  
C
        ELSE IF (IC(ITYPE+I) .EQ. 2) THEN
          BF =  EXPON*X
          GX =  EXPON*(ONE-EE*X*X)
          GY = -EXPEE*X*Y
          GZ = -EXPEE*X*Z
C                                                                       
C    Y                                                                  
C                                                                       
        ELSE IF (IC(ITYPE+I) .EQ. 3) THEN
          BF =  EXPON*Y
          GX = -EXPEE*Y*X
          GY =  EXPON*(ONE-EE*Y*Y)
          GZ = -EXPEE*Y*Z
C                                                                       
C    Z                                                                  
C                                                                       
        ELSE IF (IC(ITYPE+I) .EQ. 4) THEN
          BF =  EXPON*Z
          GX = -EXPEE*Z*X
          GY = -EXPEE*Z*Y
          GZ =  EXPON*(ONE-EE*Z*Z)
C                                                                       
C    XX                                                                
C                                                                       
        ELSE IF (IC(ITYPE+I) .EQ. 5) THEN
          BF =  EXPON*X*X
          GX = -EXPEE*X*X*X + TWO*EXPON*X
          GY = -EXPEE*X*X*Y
          GZ = -EXPEE*X*X*Z
C                                                                      
C    YY                                                               
C                                                                    
        ELSE IF (IC(ITYPE+I) .EQ. 6) THEN
          BF =  EXPON*Y*Y
          GX = -EXPEE*Y*Y*X
          GY = -EXPEE*Y*Y*Y + TWO*EXPON*Y
          GZ = -EXPEE*Y*Y*Z
C                                                                  
C    ZZ                                                             
C                                                                 
        ELSE IF (IC(ITYPE+I) .EQ. 7) THEN
          BF =  EXPON*Z*Z
          GX = -EXPEE*Z*Z*X
          GY = -EXPEE*Z*Z*Y
          GZ = -EXPEE*Z*Z*Z + TWO*EXPON*Z
C                                                                
C    XY                                                         
C                                                              
        ELSE IF (IC(ITYPE+I) .EQ. 8) THEN
          BF =  EXPON*X*Y
          GX = -EXPEE*X*Y*X + EXPON*Y
          GY = -EXPEE*X*Y*Y + EXPON*X
          GZ = -EXPEE*X*Y*Z
C                                                             
C    XZ                                                      
C                                                           
        ELSE IF (IC(ITYPE+I) .EQ. 9) THEN
          BF =  EXPON*X*Z
          GX = -EXPEE*X*Z*X + EXPON*Z
          GY = -EXPEE*X*Z*Y
          GZ = -EXPEE*X*Z*Z + EXPON*X
C                                                          
C    YZ                                                   
C                                                        
        ELSE IF (IC(ITYPE+I) .EQ. 10) THEN
          BF =  EXPON*Y*Z
          GX = -EXPEE*Y*Z*X
          GY = -EXPEE*Y*Z*Y + EXPON*Z
          GZ = -EXPEE*Y*Z*Z + EXPON*Y
C
C     XXX
C
        ELSE IF (IC(ITYPE+I) .EQ. 11) THEN
          BF =  EXPON*X*X*X
          GX = -EXPON*X*X*EE*X*X + THREE*EXPON*X*X 
          GY = -EXPON*X*X*EE*X*Y
          GZ = -EXPON*X*X*EE*X*Z
C
C     YYY 
C
        ELSE IF (IC(ITYPE+I) .EQ. 12) THEN
          BF =  EXPON*Y*Y*Y
          GX = -EXPON*Y*Y*EE*Y*X  
          GY = -EXPON*Y*Y*EE*Y*Y + THREE*EXPON*Y*Y
          GZ = -EXPON*Y*Y*EE*Y*Z
C
C     ZZZ
C
        ELSE IF (IC(ITYPE+I) .EQ. 13) THEN
          BF =  EXPON*Z*Z*Z
          GX = -EXPON*Z*Z*EE*Z*X 
          GY = -EXPON*Z*Z*EE*Z*Y
          GZ = -EXPON*Z*Z*EE*Z*Z + THREE*EXPON*Z*Z
C
C     XXY
C
        ELSE IF (IC(ITYPE+I) .EQ. 14) THEN
          BF =  EXPON*X*X*Y
          GX = -EXPON*X*Y*EE*X*X + TWO*EXPON*X*Y
          GY = -EXPON*X*X*EE*Y*Y + ONE*EXPON*X*X
          GZ = -EXPON*X*X*EE*Y*Z
C
C     XXZ 
C
        ELSE IF (IC(ITYPE+I) .EQ. 15) THEN
          BF =  EXPON*X*X*Z
          GX = -EXPON*X*Z*EE*X*X + TWO*EXPON*X*Z
          GY = -EXPON*X*X*EE*Y*Z 
          GZ = -EXPON*X*X*EE*Z*Z + ONE*EXPON*X*X
C
C     YYZ 
C
        ELSE IF (IC(ITYPE+I) .EQ. 16) THEN
          BF =  EXPON*Y*Y*Z
          GX = -EXPON*Y*Y*EE*X*Z 
          GY = -EXPON*Y*Z*EE*Y*Y + TWO*EXPON*Y*Z
          GZ = -EXPON*Y*Y*EE*Z*Z + ONE*EXPON*Y*Y
C
C     XYY 
C
        ELSE IF (IC(ITYPE+I) .EQ. 17) THEN
          BF =  EXPON*X*Y*Y
          GX = -EXPON*Y*Y*EE*X*X + ONE*EXPON*Y*Y
          GY = -EXPON*X*Y*EE*Y*Y + TWO*EXPON*X*Y
          GZ = -EXPON*Y*Y*EE*X*Z
C
C     XZZ 
C
        ELSE IF (IC(ITYPE+I) .EQ. 18) THEN
          BF =  EXPON*X*Z*Z
          GX = -EXPON*Z*Z*EE*X*X + ONE*EXPON*Z*Z
          GY = -EXPON*Z*Z*EE*X*Y 
          GZ = -EXPON*X*Z*EE*Z*Z + TWO*EXPON*X*Z
C
C     YZZ 
C
        ELSE IF (IC(ITYPE+I) .EQ. 19) THEN
          BF =  EXPON*Y*Z*Z
          GX = -EXPON*Z*Z*EE*X*Y
          GY = -EXPON*Z*Z*EE*Y*Y + ONE*EXPON*Z*Z
          GZ = -EXPON*Y*Z*EE*Z*Z + TWO*EXPON*Y*Z
C
C     XYZ
C
        ELSE IF (IC(ITYPE+I) .EQ. 20) THEN
          BF =  EXPON*X*Y*Z
          GX = -EXPON*Y*Z*EE*X*X + ONE*EXPON*Y*Z
          GY = -EXPON*X*Z*EE*Y*Y + ONE*EXPON*X*Z
          GZ = -EXPON*X*Y*EE*Z*Z + ONE*EXPON*X*Y
C
        END IF
C
C     END F-FUNCTIONS
C
C    CALCULATE DENSITY AND GRADIENT COMPONENTS FOR EACH MO.            
C
        DO 200 J = 1,NMO
          CO(IPSI+J) = CO(IPSI+J) + CO(IMO+NPRIMS*(J-1)+I)*BF
          CO(IGX+J)  = CO(IGX+J)  + CO(IMO+NPRIMS*(J-1)+I)*GX
          CO(IGY+J)  = CO(IGY+J)  + CO(IMO+NPRIMS*(J-1)+I)*GY
          CO(IGZ+J)  = CO(IGZ+J)  + CO(IMO+NPRIMS*(J-1)+I)*GZ
200   CONTINUE
      RETURN
      END
